﻿using System.Runtime.Serialization;
using System.ServiceModel;
using ProtoBuf;
using ProtoBuf.Grpc;
using ProtoBuf.Grpc.Configuration;
using ProtoBuf.Grpc.Reflection;
using ProtoBuf.Meta;

var generator = new SchemaGenerator
{
    ProtoSyntax = ProtoSyntax.Proto3
};

var schema = generator.GetSchema<IOrderService>(); // there is also a non-generic overload that takes Type
Console.WriteLine(schema);
await using var writer = new StreamWriter("services.proto");
await writer.WriteAsync(schema);

return;

//[ServiceContract] System.ServiceModel和Protobuf-net任选其一
[Service]
public interface IOrderService
{
    //[OperationContract]
    [Operation]
    Task<CreateOrderResp> CreateOrderAsync(CreateOrderReq req, CallContext context = default);
}

//[DataContract]
[ProtoContract]
public class CreateOrderReq
{
    //[DataMember(Order = 1)]
    [ProtoMember(1)]
    public string Name { get; set; }

    //[DataMember(Order = 2)]
    [ProtoMember(2)]
    public decimal Price { get; set; }
}

[DataContract]
public class CreateOrderResp
{
    //[DataMember(Order = 1)]
    [ProtoMember(1)]
    public bool Success { get; set; }

    //[DataMember(Order = 2)]
    [ProtoMember(2)]
    public int? OrderId { get; set; }
}